﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Idlesoft.Utils;
using Idlesoft.ShellAnywhereLanguage;
using Idlesoft.ShellAnywhereParser;
using Idlesoft.DataStructures.Stream;


namespace TestConsoleApp
{
	public enum ParamType : ushort
	{
		Unknown,
		Open,
		New,
		Del,
		Link,
		Target,
		Param
	}

	public enum SomethingType : ushort
	{
		Something = 1,
		SomethingMore = 2,
		TheBest = 4
	}

	class Program
	{
		static void Print(IStream<char> stream, int num)
		{

			stream.Reset();
			Console.WriteLine();
			Console.WriteLine("stream: " + num);
			//while (!stream.IsAtEnd)
			//{
			//    IChannel<char> channel = stream.Next();
			//    Console.WriteLine("channel: " + stream.Index);				
			//    while (!channel.IsAtEnd)
			//    {
			//        char c = channel.Next();
			//        Console.WriteLine(c);
			//    }
			//}
		}
		static void Main(string[] args)
		{
			try
			{

				IRegistry<IParam> registry = new Registry<IParam>();

				//verbs
				var open = new Open()
				{
					Associations = new Type[] { typeof(ITarget) }
				};


				var verbs = new IVerb[] { open };
				registry.Register(verbs);

				bool _is = open.GetType().IsType<IParam>();

				var v = registry.Find("ope");

				//targets
				var crm = new Link("crm");
				var file = new Link("open crm.txt");
				var targets = new ITarget[] { crm, file };
				registry.Register(targets);

				bool associated = open.IsAssociatedWith(crm);
				bool associated2 = open.IsAssociatedWith<ITarget>();

				//params
				var cnx = new Param("cnx.com");
				var cnn = new Param("cnn.com") { Constraints = new TypeValue[] { crm } };
				var npr = new Param("npr.org") { Constraints = new TypeValue[] { crm } };
				var npx = new Param("npx.net");
				var paramz = new IParam[] { cnx, cnn, npr, npx };
				registry.Register(paramz);

				var r0 = registry.Find<IParam, ITarget>(crm, "cn");
				//var r0 = registry.Find<IParam, ITarget>(crm, "cn");
				//var r1 = registry.Find<IParam>("cn");

				var r2 = registry.Find("c");
				var r1 = registry.Find<ITarget>("c");
				//var r2 = registry.ConstrainedBy(crm);
				//var r3 = registry.ConstrainedBy(crm).Find("np");

				var r4 = registry.Find(crm, "n");

				Parser parser = new Parser(registry, open);
				//Parser parser = new Parser(verbs, targets);




				DateTime before = DateTime.Now;
				var result = parser.Parse("open cr");
				TimeSpan duration = DateTime.Now - before;
				int seconds = duration.Seconds;
				int miliseconds = duration.Milliseconds;
				long ticks = duration.Ticks;
				result.Print();
			}
			catch (Exception ex)
			{
				ex.Print();
			}


			//var pt = SomethingType.Something | SomethingType.SomethingMore;

			//bool b1 = pt.HasFlag(SomethingType.Something);
			//bool b2 = pt.HasFlag(SomethingType.SomethingMore);
			//bool b3 = pt.HasFlag(SomethingType.TheBest);
			//var flags = pt.GetFlags();


			//IStream<char> stream1 = new Stream<char>(new char[] { 'a', 'b', 'c' });
			//stream1.AddItems(new char[] { '1', '2', '3' });
			//Print(stream1, 1);

			//IStream<char> stream2 = new Stream<char>(new char[] { 'd', 'e', 'f' });
			//stream2.AddItems(new char[] { '4', '5', '6' });
			//stream2.AddItems(new char[] { '!', '?', '#' });
			//Print(stream2, 2);

			//stream1.AddContainer(stream2);
			//Print(stream1, 1);

			//IStream<char> s1 = new Stream<char>("mike wade".ToCharArray());
			//s1.AddChannel("scott idler".ToCharArray());
			//s1.AddChannel("steve full sleves".ToCharArray());

			//IStream<char> s2 = new Stream<char>(" blows!".ToCharArray());
			//s2.AddChannel(" is awesome!".ToCharArray());
			//s2.AddChannel(" has tatoos!".ToCharArray());

			//IStream<char> s3 = s1.Append(s2);

			//char c0 = s3[3];
			//s3.Push();
			//s3.Channel = 2;
			//char c1 = s3[3];
			//s3.Pop();
			//char c2 = s3[3];


			//char[] b0 = s1.Breadth();
			//char[] b1 = s1.Breadth(2);
			//char[] b2 = s1.Breadth(4);

			//string str1 = new string(s3.Depth(0));
			//string str2 = new string(s3.Depth(1));
			//string str3 = new string(s3.Depth(2));

			//int stop = 1;
		}
	}
}
